IF (EXISTS(SELECT 1 FROM Sysobjects WHERE xtype = 'P' AND name = 'wp_ActualizarJuzgados'))
BEGIN
	DROP PROCEDURE wp_ActualizarJuzgados
END
GO

CREATE PROCEDURE wp_ActualizarJuzgados
	@idRecorrida AS int,
	@idJuzgados AS varchar(4000)
AS

UPDATE judiciales.dbo.Juzgados
SET idSede = NULL
WHERE idSede = @idRecorrida

UPDATE judiciales.dbo.Juzgados
SET idSede = @idRecorrida
WHERE id IN (SELECT VALUE FROM fn_Split(@idJuzgados, ','))

